package com.transaction.demo.notify.biz.impl;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.transaction.demo.notify.entity.NotifyRecordLogBean;
import com.transaction.demo.common.util.ResultPage;
import com.transaction.demo.notify.vo.req.NotifyRecordLogReqVo;
import com.transaction.demo.notify.vo.req.NotifyRecordLogListReqVo;
import com.transaction.demo.notify.vo.req.NotifyRecordLogAddReqVo;
import com.transaction.demo.notify.vo.req.NotifyRecordLogUpdateReqVo;
import com.transaction.demo.notify.vo.resp.NotifyRecordLogRespVo;
import com.transaction.demo.notify.dao.NotifyRecordLogDao;
import com.transaction.demo.notify.biz.NotifyRecordLogBiz;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

/**
 * 描述：通知记录日志表 RP_NOTIFY_RECORD_LOG
 * 作者：马庆智
 * 日期：2023/04/27 17:18:42
 */
@Service
public class NotifyRecordLogBizImpl implements NotifyRecordLogBiz {

   @Autowired
   private NotifyRecordLogDao notifyRecordLogDao;

   /**
    * 查询通知记录日志表 RP_NOTIFY_RECORD_LOG
    *
    * @param notifyRecordLog 请求参数
    * @return NotifyRecordLogResp
    * @author 马庆智
    * @date: 2023/04/27 17:18:42
    */
   @Override
   public NotifyRecordLogRespVo queryNotifyRecordLog(NotifyRecordLogReqVo notifyRecordLog){

       NotifyRecordLogBean query = notifyRecordLogDao.queryNotifyRecordLog(NotifyRecordLogBean.builder().build());

       return NotifyRecordLogRespVo.builder().build();
   }

   /**
    * 查询通知记录日志表 RP_NOTIFY_RECORD_LOG列表
    *
    * @param notifyRecordLog 请求参数
    * @return NotifyRecordLogResp
    * @author 马庆智
    * @date: 2023/04/27 17:18:42
    */
   @Override
   public ResultPage<NotifyRecordLogRespVo> queryNotifyRecordLogList(NotifyRecordLogListReqVo notifyRecordLog){

       PageHelper.startPage(notifyRecordLog.getCurrent(), notifyRecordLog.getPageSize());
	   List<NotifyRecordLogBean> query = notifyRecordLogDao.queryNotifyRecordLogList(NotifyRecordLogBean.builder()
               .merchantOrderNo(notifyRecordLog.getMerchantOrderNo()).build());
       PageInfo<NotifyRecordLogBean> pageInfo = new PageInfo<>(query);

	   List<NotifyRecordLogRespVo> list = pageInfo.getList().stream().map(x -> {
		   NotifyRecordLogRespVo resp = new NotifyRecordLogRespVo();
		   BeanUtils.copyProperties(x, resp);
		   return resp;
	   }).collect(Collectors.toList());

        return new ResultPage<>(list,pageInfo.getPageNum(),pageInfo.getPageSize(),pageInfo.getTotal());

   }

   /**
    * 添加通知记录日志表 RP_NOTIFY_RECORD_LOG
    *
    * @param notifyRecordLog 请求参数
    * @return int
    * @author 马庆智
    * @date: 2023/04/27 17:18:42
    */
   @Override
   public int saveNotifyRecordLog(NotifyRecordLogAddReqVo notifyRecordLog){
       NotifyRecordLogBean bean = new NotifyRecordLogBean();
       BeanUtils.copyProperties(notifyRecordLog,bean);
       return notifyRecordLogDao.saveNotifyRecordLog(bean);
   }

   /**
    * 删除通知记录日志表 RP_NOTIFY_RECORD_LOG
    *
    * @param ids 请求参数
    * @return int
    * @author 马庆智
    * @date: 2023/04/27 17:18:42
    */
   @Override
   public int deleteNotifyRecordLog(String ids){
		return notifyRecordLogDao.deleteNotifyRecordLog(Arrays.stream(ids.split(",")).map(Integer::parseInt).collect(Collectors.toList()));
   }

   /**
    * 更新通知记录日志表 RP_NOTIFY_RECORD_LOG
    *
    * @param notifyRecordLog 请求参数
    * @return int
    * @author 马庆智
    * @date: 2023/04/27 17:18:42
    */
   @Override
   public int updateNotifyRecordLog(NotifyRecordLogUpdateReqVo notifyRecordLog){
       NotifyRecordLogBean bean = new NotifyRecordLogBean();
       BeanUtils.copyProperties(notifyRecordLog,bean);
        return notifyRecordLogDao.updateNotifyRecordLog(bean);
   }

}